// backbone Model and Collection test
var data = {
	jobCatList :[
		{
	    	id : "cat1",
	    	name : "扶老奶奶",
	    	jobList:[
		    	{id:"1",name:"a"},
		    	{id:"2",name:"b"}
		    ]
	    },
		{
	    	id : "cat2",
	    	name : "过大马路",
	    	jobList:[
		    	{id:"3",name:"c"},
		    	{id:"4",name:"b"}
		    ]
	    },
		{
	    	id : "cat3",
	    	name : "被车撞了",
	    	jobList:[
		    	{id:"5",name:"e"},
		    	{id:"6",name:"f"}
		    ]
	    }
	]
};
var App ={
	Job:{},
	Fight:{}
};
$(function(){
    App.Job.JobModel = MVC.Model.extend({
    	defaults:{
    		id:"",
    		name:""
    	},
		initialize : function(args){
			VCM.debug("JobModel initialize",args);
		},
		dojob : function(){
			VCM.debug("JobModel dojob",this.attr(id));
		}
    });
    //初始化模型赋值
    //var job = new App.Job.JobModel({"name":"shit"});
    //使用set赋值
	//var job = new App.Job.JobModel();
	//job.set({"name":"shit"});
    
    
    //job collection
    App.Job.JobList = MVC.Collection.extend({
    	model : App.Job.JobModel,
    	initialize: function(args){
    		VCM.debug("JobList initialize", args );
        }
    });
//    初始化集合赋值
//    var jobList1 = new App.Job.JobList([
//    	{id:"1",name:"a"},
//    	{id:"2",name:"b"}
//    ]);
//    var jobList2 = new App.Job.JobList([
//    	{id:"3",name:"c"},
//    	{id:"4",name:"d"}
//    ]);

    //job catalog model
    App.Job.JobCatModel = MVC.Model.extend({
    	defaults:{
    		id:"",
    		name:"",
    		jobList:null
    	},
		initialize : function(args){
			VCM.debug("JobCatModel initialize", args );
			 _.isArray(args.jobList) && this.set("jobList" , new App.Job.JobList(args.jobList) );
		}
    });
    
    //job catalog collection
    App.Job.JobCatList = MVC.Collection.extend({
    	model : App.Job.JobCatModel,
    	initialize: function(args){
    		VCM.debug("JobCatList initialize", args );
        }
    });
	
//    var jobCatList = new App.Job.JobCatList();
    
	  //使用collection 的 add 方法赋值
//    jobCatList.add({
//    	id : "cat1",
//    	name : "扶老奶奶",
//    	jobList:[
//	    	{id:"1",name:"a"},
//	    	{id:"2",name:"b"}
//	    ]
//    });
    
    
//    jobCatList.add({
//    	id : "cat2",
//    	name : "过大马路",
//    	jobList:new App.Job.JobList([
//	    	{id:"3",name:"c"},
//	    	{id:"4",name:"d"}
//	    ])
//    });

	//初始化集合赋值
	var jobCatList = new App.Job.JobCatList(data.jobCatList);
    
    VCM.debug("jobCatList",jobCatList);
    
   	jobCatList.each(function(jobCat){
   		VCM.debug(jobCat.get("name"),jobCat);
   		jobCat.get("jobList").each(function(job){
   			VCM.debug(job.get("name"),job);
   		});
   	});
   	
});


